home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / m2c / IO.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  19KB  |  1,054 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_General
  4. #include "General.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_Memory
  8. #include "Memory.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_System
  12. #include "System.h"
  13. #endif
  14.  
  15. #ifndef DEFINITION_IO
  16. #include "IO.h"
  17. #endif
  18.  
  19.  
  20. #define EolCh    '\n'
  21. #define TabCh    '\t'
  22. #define BufferSize    1024
  23. #define MaxInt    2147483647
  24. #define MaxPow10    1000000000
  25. #define MaxIntDiv10    (MaxInt / 10)
  26. typedef struct S_1 {
  27.     struct S_2 {
  28.         CHAR A[BufferSize + 1];
  29.     } *Buffer;
  30.     SHORTINT BufferIndex;
  31.     SHORTINT BytesRead;
  32.     BOOLEAN OpenForOutput;
  33.     BOOLEAN EndOfFile;
  34.     BOOLEAN FlushLine;
  35. } BufferDescriptor;
  36. static struct S_3 {
  37.     BufferDescriptor A[System_cMaxFile - -1 + 1];
  38. } BufferPool;
  39. static IO_tFile i;
  40. static struct S_4 {
  41.     CHAR A[15 + 1];
  42. } MyCHR;
  43. static void FillBuffer ARGS((IO_tFile f));
  44. struct S_9 {
  45.     CHAR A[100000000 + 1];
  46. };
  47. static void CheckFlushLine ARGS((IO_tFile f));
  48. struct S_10 {
  49.     CHAR A[100000000 + 1];
  50. };
  51. struct S_11 {
  52.     CHAR A[10 + 1];
  53. };
  54. #define StartIndex    100
  55. struct S_12 {
  56.     CARDINAL A[200 + 1];
  57. };
  58. struct S_13 {
  59.     CHAR A[32 + 1];
  60. };
  61. struct S_14 {
  62.     CHAR A[10 + 1];
  63. };
  64.  
  65.  
  66. static void FillBuffer
  67. # ifdef __STDC__
  68. (IO_tFile f)
  69. # else
  70. (f)
  71. IO_tFile f;
  72. # endif
  73. {
  74.   {
  75.     register BufferDescriptor *W_1 = &BufferPool.A[f - -1];
  76.  
  77.     if (W_1->FlushLine) {
  78.       IO_WriteFlush((System_tFile)IO_StdOutput);
  79.       IO_WriteFlush((System_tFile)IO_StdError);
  80.     }
  81.     W_1->BufferIndex = 0;
  82.     W_1->BytesRead = Read(f, ADR(W_1->Buffer->A[1]), (LONGCARD)BufferSize);
  83.     if (W_1->BytesRead <= 0) {
  84.       W_1->BytesRead = 0;
  85.       W_1->EndOfFile = TRUE;
  86.     }
  87.   }
  88. }
  89.  
  90. IO_tFile IO_ReadOpen
  91. # ifdef __STDC__
  92. (CHAR FileName[], LONGCARD O_1)
  93. # else
  94. (FileName, O_1)
  95. CHAR FileName[];
  96. LONGCARD O_1;
  97. # endif
  98. {
  99.   IO_tFile f;
  100.  
  101.   f = OpenInput(FileName, O_1);
  102.   {
  103.     register BufferDescriptor *W_2 = &BufferPool.A[f - -1];
  104.  
  105.     W_2->Buffer = (struct S_2 *)Memory_Alloc((LONGINT)(BufferSize + 1));
  106.     W_2->BufferIndex = 0;
  107.     W_2->BytesRead = 0;
  108.     W_2->OpenForOutput = FALSE;
  109.     W_2->EndOfFile = FALSE;
  110.   }
  111.   CheckFlushLine(f);
  112.   return f;
  113. }
  114.  
  115. void IO_ReadClose
  116. # ifdef __STDC__
  117. (IO_tFile f)
  118. # else
  119. (f)
  120. IO_tFile f;
  121. # endif
  122. {
  123.   Close(f);
  124.   {
  125.     register BufferDescriptor *W_3 = &BufferPool.A[f - -1];
  126.  
  127.     Memory_Free((LONGINT)(BufferSize + 1), (ADDRESS)W_3->Buffer);
  128.     W_3->Buffer = NIL;
  129.   }
  130. }
  131.  
  132. INTEGER IO_Read
  133. # ifdef __STDC__
  134. (IO_tFile f, ADDRESS Buffer, CARDINAL Size)
  135. # else
  136. (f, Buffer, Size)
  137. IO_tFile f;
  138. ADDRESS Buffer;
  139. CARDINAL Size;
  140. # endif
  141. {
  142.   struct S_9 *BufferPtr;
  143.   CARDINAL i;
  144.  
  145.   BufferPtr = (struct S_9 *)Buffer;
  146.   {
  147.     register BufferDescriptor *W_4 = &BufferPool.A[f - -1];
  148.  
  149.     i = 0;
  150.     for (;;) {
  151.       if (i == Size) {
  152.         return i;
  153.       }
  154.       if (W_4->BufferIndex == W_4->BytesRead) {
  155.         FillBuffer(f);
  156.         if (W_4->EndOfFile) {
  157.           W_4->Buffer->A[1] = '\0';
  158.         }
  159.       }
  160.       INC(W_4->BufferIndex);
  161.       BufferPtr->A[i] = W_4->Buffer->A[W_4->BufferIndex];
  162.       if (W_4->EndOfFile) {
  163.         return i;
  164.       }
  165.       INC(i);
  166.     } EXIT_1:;
  167.   }
  168. }
  169.  
  170. CHAR IO_ReadC
  171. # ifdef __STDC__
  172. (IO_tFile f)
  173. # else
  174. (f)
  175. IO_tFile f;
  176. # endif
  177. {
  178.   {
  179.     register BufferDescriptor *W_5 = &BufferPool.A[f - -1];
  180.  
  181.     if (W_5->BufferIndex == W_5->BytesRead) {
  182.       FillBuffer(f);
  183.       if (W_5->EndOfFile) {
  184.         W_5->Buffer->A[1] = '\0';
  185.       }
  186.     }
  187.     INC(W_5->BufferIndex);
  188.     return W_5->Buffer->A[W_5->BufferIndex];
  189.   }
  190. }
  191.  
  192. INTEGER IO_ReadI
  193. # ifdef __STDC__
  194. (IO_tFile f)
  195. # else
  196. (f)
  197. IO_tFile f;
  198. # endif
  199. {
  200.   INTEGER n;
  201.   CHAR ch;
  202.   BOOLEAN negative;
  203.  
  204.   do {
  205.     ch = IO_ReadC(f);
  206.   } while (!(ch != ' ' && ch != TabCh && ch != EolCh));
  207.   switch (ch) {
  208.   case '+':;
  209.     negative = FALSE;
  210.     ch = IO_ReadC(f);
  211.     break;
  212.   case '-':;
  213.     negative = TRUE;
  214.     ch = IO_ReadC(f);
  215.     break;
  216.   default :
  217.     negative = FALSE;
  218.     break;
  219.   }
  220.   n = 0;
  221.   while ('0' <= ch && ch <= '9') {
  222.     n = 10 * n + (INTEGER)(ORD(ch) - ORD('0'));
  223.     ch = IO_ReadC(f);
  224.   }
  225.   DEC(BufferPool.A[f - -1].BufferIndex);
  226.   if (negative) {
  227.     return -n;
  228.   } else {
  229.     return n;
  230.   }
  231. }
  232.  
  233. REAL IO_ReadR
  234. # ifdef __STDC__
  235. (IO_tFile f)
  236. # else
  237. (f)
  238. IO_tFile f;
  239. # endif
  240. {
  241.   REAL n;
  242.   LONGCARD Mantissa;
  243.   INTEGER Exponent;
  244.   BOOLEAN MantissaNeg;
  245.   BOOLEAN ExponentNeg;
  246.   CARDINAL FractionDigits;
  247.   CARDINAL TruncatedDigits;
  248.   CHAR ch;
  249.  
  250.   MantissaNeg = FALSE;
  251.   Mantissa = 0;
  252.   Exponent = 0;
  253.   FractionDigits = 0;
  254.   TruncatedDigits = 0;
  255.   do {
  256.     ch = IO_ReadC(f);
  257.   } while (!(ch != ' ' && ch != TabCh && ch != EolCh));
  258.   switch (ch) {
  259.   case '+':;
  260.     ch = IO_ReadC(f);
  261.     break;
  262.   case '-':;
  263.     ch = IO_ReadC(f);
  264.     MantissaNeg = TRUE;
  265.     break;
  266.   case 'E':;
  267.     Mantissa = 1;
  268.     break;
  269.   default :
  270.     break;
  271.   }
  272.   while ('0' <= ch && ch <= '9') {
  273.     if (Mantissa <= MaxIntDiv10) {
  274.       Mantissa = 10 * Mantissa;
  275.       if (Mantissa <= MaxInt - (ORD(ch) - ORD('0'))) {
  276.         INC1(Mantissa, ORD(ch) - ORD('0'));
  277.       } else {
  278.         INC(TruncatedDigits);
  279.       }
  280.     } else {
  281.       INC(TruncatedDigits);
  282.     }
  283.     ch = IO_ReadC(f);
  284.   }
  285.   if (ch == '.') {
  286.     ch = IO_ReadC(f);
  287.   }
  288.   while ('0' <= ch && ch <= '9') {
  289.     if (Mantissa <= MaxIntDiv10) {
  290.       Mantissa = 10 * Mantissa;
  291.       if (Mantissa <= MaxInt - (ORD(ch) - ORD('0'))) {
  292.         INC1(Mantissa, ORD(ch) - ORD('0'));
  293.       } else {
  294.         INC(TruncatedDigits);
  295.       }
  296.     } else {
  297.       INC(TruncatedDigits);
  298.     }
  299.     INC(FractionDigits);
  300.     ch = IO_ReadC(f);
  301.   }
  302.   if (ch == 'E') {
  303.     ch = IO_ReadC(f);
  304.     switch (ch) {
  305.     case '+':;
  306.       ExponentNeg = FALSE;
  307.       ch = IO_ReadC(f);
  308.       break;
  309.     case '-':;
  310.       ExponentNeg = TRUE;
  311.       ch = IO_ReadC(f);
  312.       break;
  313.     default :
  314.       ExponentNeg = FALSE;
  315.       break;
  316.     }
  317.     while ('0' <= ch && ch <= '9') {
  318.       Exponent = 10 * Exponent + (INTEGER)(ORD(ch) - ORD('0'));
  319.       ch = IO_ReadC(f);
  320.     }
  321.     if (ExponentNeg) {
  322.       Exponent = -Exponent;
  323.     }
  324.   }
  325.   DEC(BufferPool.A[f - -1].BufferIndex);
  326.   DEC1(Exponent, FractionDigits - TruncatedDigits);
  327.   n = FLOAT(Mantissa) * General_Exp10(Exponent);
  328.   if (MantissaNeg) {
  329.     return -n;
  330.   } else {
  331.     return n;
  332.   }
  333. }
  334.  
  335. BOOLEAN IO_ReadB
  336. # ifdef __STDC__
  337. (IO_tFile f)
  338. # else
  339. (f)
  340. IO_tFile f;
  341. # endif
  342. {
  343.   return IO_ReadC(f) == 'T';
  344. }
  345.  
  346. INTEGER IO_ReadN
  347. # ifdef __STDC__
  348. (IO_tFile f, INTEGER Base)
  349. # else
  350. (f, Base)
  351. IO_tFile f;
  352. INTEGER Base;
  353. # endif
  354. {
  355.   INTEGER n;
  356.   CHAR ch;
  357.   INTEGER digit;
  358.  
  359.   do {
  360.     ch = IO_ReadC(f);
  361.   } while (!(ch != ' ' && ch != TabCh && ch != EolCh));
  362.   n = 0;
  363.   for (;;) {
  364.     if ('0' <= ch && ch <= '9') {
  365.       digit = ORD(ch) - ORD('0');
  366.     } else if ('A' <= ch && ch <= 'F') {
  367.       digit = ORD(ch) - ORD('A') + 10;
  368.     } else {
  369.       digit = 99;
  370.     }
  371.     if (digit >= Base) {
  372.       goto EXIT_2;
  373.     }
  374.     n = Base * n + digit;
  375.     ch = IO_ReadC(f);
  376.   } EXIT_2:;
  377.   DEC(BufferPool.A[f - -1].BufferIndex);
  378.   return n;
  379. }
  380.  
  381. void IO_ReadS
  382. # ifdef __STDC__
  383. (IO_tFile f, CHAR s[], LONGCARD O_2)
  384. # else
  385. (f, s, O_2)
  386. IO_tFile f;
  387. CHAR s[];
  388. LONGCARD O_2;
  389. # endif
  390. {
  391.   CARDINAL i;
  392.  
  393.   {
  394.     register BufferDescriptor *W_6 = &BufferPool.A[f - -1];
  395.  
  396.     {
  397.       LONGCARD B_1 = 0, B_2 = (O_2 - 1);
  398.  
  399.       if (B_1 <= B_2)
  400.         for (i = B_1;; i += 1) {
  401.           if (W_6->BufferIndex == W_6->BytesRead) {
  402.             FillBuffer(f);
  403.             if (W_6->EndOfFile) {
  404.               W_6->Buffer->A[1] = '\0';
  405.             }
  406.           }
  407.           INC(W_6->BufferIndex);
  408.           s[i] = W_6->Buffer->A[W_6->BufferIndex];
  409.           if (i >= B_2) break;
  410.         }
  411.     }
  412.   }
  413. }
  414.  
  415. SHORTINT IO_ReadShort
  416. # ifdef __STDC__
  417. (IO_tFile f)
  418. # else
  419. (f)
  420. IO_tFile f;
  421. # endif
  422. {
  423.   return IO_ReadI(f);
  424. }
  425.  
  426. LONGINT IO_ReadLong
  427. # ifdef __STDC__
  428. (IO_tFile f)
  429. # else
  430. (f)
  431. IO_tFile f;
  432. # endif
  433. {
  434.   return IO_ReadI(f);
  435. }
  436.  
  437. CARDINAL IO_ReadCard
  438. # ifdef __STDC__
  439. (IO_tFile f)
  440. # else
  441. (f)
  442. IO_tFile f;
  443. # endif
  444. {
  445.   return IO_ReadI(f);
  446. }
  447.  
  448. void IO_ReadNl
  449. # ifdef __STDC__
  450. (IO_tFile f)
  451. # else
  452. (f)
  453. IO_tFile f;
  454. # endif
  455. {
  456.   do {
  457.   } while (!(IO_ReadC(f) == EolCh));
  458. }
  459.  
  460. void IO_UnRead
  461. # ifdef __STDC__
  462. (IO_tFile f)
  463. # else
  464. (f)
  465. IO_tFile f;
  466. # endif
  467. {
  468.   DEC(BufferPool.A[f - -1].BufferIndex);
  469. }
  470.  
  471. BOOLEAN IO_EndOfLine
  472. # ifdef __STDC__
  473. (IO_tFile f)
  474. # else
  475. (f)
  476. IO_tFile f;
  477. # endif
  478. {
  479.   CHAR ch;
  480.  
  481.   {
  482.     register BufferDescriptor *W_7 = &BufferPool.A[f - -1];
  483.  
  484.     if (W_7->BufferIndex == W_7->BytesRead) {
  485.       FillBuffer(f);
  486.       if (W_7->EndOfFile) {
  487.         W_7->Buffer->A[1] = '\0';
  488.       }
  489.     }
  490.     return W_7->Buffer->A[W_7->BufferIndex + 1] == EolCh;
  491.   }
  492. }
  493.  
  494. BOOLEAN IO_EndOfFile
  495. # ifdef __STDC__
  496. (IO_tFile f)
  497. # else
  498. (f)
  499. IO_tFile f;
  500. # endif
  501. {
  502.   CHAR ch;
  503.  
  504.   ch = IO_ReadC(f);
  505.   DEC(BufferPool.A[f - -1].BufferIndex);
  506.   return BufferPool.A[f - -1].EndOfFile;
  507. }
  508.  
  509. static void CheckFlushLine
  510. # ifdef __STDC__
  511. (IO_tFile f)
  512. # else
  513. (f)
  514. IO_tFile f;
  515. # endif
  516. {
  517.   BufferPool.A[f - -1].FlushLine = IsCharacterSpecial(f);
  518. }
  519.  
  520. IO_tFile IO_WriteOpen
  521. # ifdef __STDC__
  522. (CHAR FileName[], LONGCARD O_3)
  523. # else
  524. (FileName, O_3)
  525. CHAR FileName[];
  526. LONGCARD O_3;
  527. # endif
  528. {
  529.   IO_tFile f;
  530.  
  531.   f = OpenOutput(FileName, O_3);
  532.   {
  533.     register BufferDescriptor *W_8 = &BufferPool.A[f - -1];
  534.  
  535.     W_8->Buffer = (struct S_2 *)Memory_Alloc((LONGINT)(BufferSize + 1));
  536.     W_8->BufferIndex = 0;
  537.     W_8->OpenForOutput = TRUE;
  538.   }
  539.   CheckFlushLine(f);
  540.   return f;
  541. }
  542.  
  543. void IO_WriteClose
  544. # ifdef __STDC__
  545. (IO_tFile f)
  546. # else
  547. (f)
  548. IO_tFile f;
  549. # endif
  550. {
  551.   IO_WriteFlush(f);
  552.   Close(f);
  553.   {
  554.     register BufferDescriptor *W_9 = &BufferPool.A[f - -1];
  555.  
  556.     Memory_Free((LONGINT)(BufferSize + 1), (ADDRESS)W_9->Buffer);
  557.     W_9->Buffer = NIL;
  558.   }
  559. }
  560.  
  561. void IO_WriteFlush
  562. # ifdef __STDC__
  563. (IO_tFile f)
  564. # else
  565. (f)
  566. IO_tFile f;
  567. # endif
  568. {
  569.   {
  570.     register BufferDescriptor *W_10 = &BufferPool.A[f - -1];
  571.  
  572.     W_10->BytesRead = Write(f, ADR(W_10->Buffer->A[1]), (LONGCARD)W_10->BufferIndex);
  573.     W_10->BufferIndex = 0;
  574.   }
  575. }
  576.  
  577. INTEGER IO_Write
  578. # ifdef __STDC__
  579. (IO_tFile f, ADDRESS Buffer, INTEGER Size)
  580. # else
  581. (f, Buffer, Size)
  582. IO_tFile f;
  583. ADDRESS Buffer;
  584. INTEGER Size;
  585. # endif
  586. {
  587.   struct S_10 *BufferPtr;
  588.   INTEGER i;
  589.  
  590.   BufferPtr = (struct S_10 *)Buffer;
  591.   {
  592.     register BufferDescriptor *W_11 = &BufferPool.A[f - -1];
  593.  
  594.     {
  595.       LONGINT B_3 = 0, B_4 = Size - 1;
  596.  
  597.       if (B_3 <= B_4)
  598.         for (i = B_3;; i += 1) {
  599.           INC(W_11->BufferIndex);
  600.           W_11->Buffer->A[W_11->BufferIndex] = BufferPtr->A[i];
  601.           if (W_11->BufferIndex == BufferSize) {
  602.             IO_WriteFlush(f);
  603.           }
  604.           if (i >= B_4) break;
  605.         }
  606.     }
  607.   }
  608.   return Size;
  609. }
  610.  
  611. void IO_WriteC
  612. # ifdef __STDC__
  613. (IO_tFile f, CHAR c)
  614. # else
  615. (f, c)
  616. IO_tFile f;
  617. CHAR c;
  618. # endif
  619. {
  620.   {
  621.     register BufferDescriptor *W_12 = &BufferPool.A[f - -1];
  622.  
  623.     INC(W_12->BufferIndex);
  624.     W_12->Buffer->A[W_12->BufferIndex] = c;
  625.     if (W_12->BufferIndex == BufferSize || W_12->FlushLine && c == EolCh) {
  626.       IO_WriteFlush(f);
  627.     }
  628.   }
  629. }
  630.  
  631. void IO_WriteI
  632. # ifdef __STDC__
  633. (IO_tFile f, INTEGER n, CARDINAL FieldWidth)
  634. # else
  635. (f, n, FieldWidth)
  636. IO_tFile f;
  637. INTEGER n;
  638. CARDINAL FieldWidth;
  639. # endif
  640. {
  641.   INTEGER i;
  642.   CARDINAL length;
  643.   CARDINAL negative;
  644.   struct S_11 digits;
  645.  
  646.   if (n < 0) {
  647.     negative = 1;
  648.     n = -n;
  649.   } else {
  650.     negative = 0;
  651.   }
  652.   length = 0;
  653.   do {
  654.     INC(length);
  655.     digits.A[length] = MyCHR.A[n % 10];
  656.     n = n / 10;
  657.   } while (!(n == 0));
  658.   {
  659.     LONGINT B_5 = 1, B_6 = (INTEGER)(FieldWidth - length - negative);
  660.  
  661.     if (B_5 <= B_6)
  662.       for (i = B_5;; i += 1) {
  663.         IO_WriteC(f, ' ');
  664.         if (i >= B_6) break;
  665.       }
  666.   }
  667.   if (negative == 1) {
  668.     IO_WriteC(f, '-');
  669.   }
  670.   for (i = (INTEGER)length; i >= 1; i += -1) {
  671.     IO_WriteC(f, digits.A[i]);
  672.   }
  673. }
  674.  
  675. void IO_WriteR
  676. # ifdef __STDC__
  677. (IO_tFile f, REAL n, CARDINAL Before, CARDINAL After, CARDINAL Exp)
  678. # else
  679. (f, n, Before, After, Exp)
  680. IO_tFile f;
  681. REAL n;
  682. CARDINAL Before, After, Exp;
  683. # endif
  684. {
  685.   CARDINAL i;
  686.   INTEGER j;
  687.   CARDINAL FirstDigit;
  688.   CARDINAL IntegerDigits;
  689.   CARDINAL TotalDigits;
  690.   CARDINAL IsNegative;
  691.   struct S_12 Digits;
  692.   REAL MaxCard;
  693.   REAL MaxCardDiv10;
  694.   LONGCARD Mantissa;
  695.   INTEGER Exponent;
  696.  
  697.   MaxCard = FLOAT(MaxInt);
  698.   MaxCardDiv10 = FLOAT(MaxIntDiv10);
  699.   if (n < 0.0) {
  700.     IsNegative = 1;
  701.     n = -n;
  702.   } else {
  703.     IsNegative = 0;
  704.   }
  705.   if (n == 0.0) {
  706.     Mantissa = 0;
  707.     Exponent = 1;
  708.   } else {
  709.     Exponent = 10;
  710.     while (n > MaxCard) {
  711.       n = n / 10.0;
  712.       INC(Exponent);
  713.     }
  714.     while (n <= MaxCardDiv10) {
  715.       n = n * 10.0;
  716.       DEC(Exponent);
  717.     }
  718.     Mantissa = TRUNC(n);
  719.     if (Mantissa < MaxPow10) {
  720.       DEC(Exponent);
  721.     }
  722.   }
  723.   if (Exp > 0 || Exponent <= 0) {
  724.     IntegerDigits = 1;
  725.   } else {
  726.     IntegerDigits = Exponent;
  727.   }
  728.   if (After == 0) {
  729.     After = 1;
  730.   }
  731.   TotalDigits = IntegerDigits + After;
  732.   FirstDigit = StartIndex;
  733.   do {
  734.     DEC(FirstDigit);
  735.     Digits.A[FirstDigit] = Mantissa % 10;
  736.     Mantissa = Mantissa / 10;
  737.   } while (!(Mantissa == 0));
  738.   if (Exp == 0) {
  739.     {
  740.       LONGINT B_7 = 1, B_8 = 1 - Exponent;
  741.  
  742.       if (B_7 <= B_8)
  743.         for (j = B_7;; j += 1) {
  744.           DEC(FirstDigit);
  745.           Digits.A[FirstDigit] = 0;
  746.           if (j >= B_8) break;
  747.         }
  748.     }
  749.   }
  750.   {
  751.     LONGCARD B_9 = StartIndex, B_10 = FirstDigit + TotalDigits;
  752.  
  753.     if (B_9 <= B_10)
  754.       for (i = B_9;; i += 1) {
  755.         Digits.A[i] = 0;
  756.         if (i >= B_10) break;
  757.       }
  758.   }
  759.   Digits.A[FirstDigit - 1] = 0;
  760.   if (Digits.A[FirstDigit + TotalDigits] >= 5) {
  761.     i = FirstDigit + TotalDigits - 1;
  762.     while (Digits.A[i] == 9) {
  763.       Digits.A[i] = 0;
  764.       DEC(i);
  765.     }
  766.     INC(Digits.A[i]);
  767.     if (i == FirstDigit - 1) {
  768.       FirstDigit = i;
  769.       if (Exp > 0) {
  770.         INC(Exponent);
  771.       } else if (Exponent > 0) {
  772.         INC(IntegerDigits);
  773.       }
  774.     }
  775.   }
  776.   {
  777.     LONGINT B_11 = 1, B_12 = (INTEGER)(Before - IsNegative - IntegerDigits);
  778.  
  779.     if (B_11 <= B_12)
  780.       for (j = B_11;; j += 1) {
  781.         IO_WriteC(f, ' ');
  782.         if (j >= B_12) break;
  783.       }
  784.   }
  785.   if (IsNegative == 1) {
  786.     IO_WriteC(f, '-');
  787.   }
  788.   {
  789.     LONGCARD B_13 = 1, B_14 = IntegerDigits;
  790.  
  791.     if (B_13 <= B_14)
  792.       for (i = B_13;; i += 1) {
  793.         IO_WriteC(f, MyCHR.A[Digits.A[FirstDigit]]);
  794.         INC(FirstDigit);
  795.         if (i >= B_14) break;
  796.       }
  797.   }
  798.   IO_WriteC(f, '.');
  799.   {
  800.     LONGCARD B_15 = 1, B_16 = After;
  801.  
  802.     if (B_15 <= B_16)
  803.       for (i = B_15;; i += 1) {
  804.         IO_WriteC(f, MyCHR.A[Digits.A[FirstDigit]]);
  805.         INC(FirstDigit);
  806.         if (i >= B_16) break;
  807.       }
  808.   }
  809.   if (Exp > 0) {
  810.     DEC(Exponent);
  811.     IO_WriteC(f, 'E');
  812.     if (Exponent < 0) {
  813.       IO_WriteC(f, '-');
  814.       Exponent = -Exponent;
  815.     } else {
  816.       IO_WriteC(f, '+');
  817.     }
  818.     IO_WriteN(f, (LONGCARD)Exponent, Exp - 1, 10L);
  819.   }
  820. }
  821.  
  822. void IO_WriteB
  823. # ifdef __STDC__
  824. (IO_tFile f, BOOLEAN b)
  825. # else
  826. (f, b)
  827. IO_tFile f;
  828. BOOLEAN b;
  829. # endif
  830. {
  831.   if (b) {
  832.     IO_WriteC(f, 'T');
  833.   } else {
  834.     IO_WriteC(f, 'F');
  835.   }
  836. }
  837.  
  838. void IO_WriteN
  839. # ifdef __STDC__
  840. (IO_tFile f, LONGCARD n, CARDINAL FieldWidth, CARDINAL Base)
  841. # else
  842. (f, n, FieldWidth, Base)
  843. IO_tFile f;
  844. LONGCARD n;
  845. CARDINAL FieldWidth, Base;
  846. # endif
  847. {
  848.   INTEGER i;
  849.   CARDINAL length;
  850.   struct S_13 digits;
  851.  
  852.   length = 0;
  853.   do {
  854.     INC(length);
  855.     digits.A[length] = MyCHR.A[n % Base];
  856.     n = n / Base;
  857.   } while (!(n == 0));
  858.   {
  859.     LONGINT B_17 = 1, B_18 = (INTEGER)(FieldWidth - length);
  860.  
  861.     if (B_17 <= B_18)
  862.       for (i = B_17;; i += 1) {
  863.         IO_WriteC(f, '0');
  864.         if (i >= B_18) break;
  865.       }
  866.   }
  867.   for (i = (INTEGER)length; i >= 1; i += -1) {
  868.     IO_WriteC(f, digits.A[i]);
  869.   }
  870. }
  871.  
  872. void IO_WriteS
  873. # ifdef __STDC__
  874. (IO_tFile f, CHAR s[], LONGCARD O_4)
  875. # else
  876. (f, s, O_4)
  877. IO_tFile f;
  878. CHAR s[];
  879. LONGCARD O_4;
  880. # endif
  881. {
  882.   CARDINAL i;
  883.   CHAR c;
  884.  
  885.   {
  886.     register BufferDescriptor *W_13 = &BufferPool.A[f - -1];
  887.  
  888.     {
  889.       LONGCARD B_19 = 0, B_20 = (O_4 - 1);
  890.  
  891.       if (B_19 <= B_20)
  892.         for (i = B_19;; i += 1) {
  893.           c = s[i];
  894.           if (c == '\0') {
  895.             return;
  896.           }
  897.           INC(W_13->BufferIndex);
  898.           W_13->Buffer->A[W_13->BufferIndex] = c;
  899.           if (W_13->BufferIndex == BufferSize || W_13->FlushLine && c == EolCh) {
  900.             IO_WriteFlush(f);
  901.           }
  902.           if (i >= B_20) break;
  903.         }
  904.     }
  905.   }
  906. }
  907.  
  908. void IO_WriteShort
  909. # ifdef __STDC__
  910. (IO_tFile f, SHORTINT n, CARDINAL FieldWidth)
  911. # else
  912. (f, n, FieldWidth)
  913. IO_tFile f;
  914. SHORTINT n;
  915. CARDINAL FieldWidth;
  916. # endif
  917. {
  918.   IO_WriteI(f, (LONGINT)n, FieldWidth);
  919. }
  920.  
  921. void IO_WriteLong
  922. # ifdef __STDC__
  923. (IO_tFile f, LONGINT n, CARDINAL FieldWidth)
  924. # else
  925. (f, n, FieldWidth)
  926. IO_tFile f;
  927. LONGINT n;
  928. CARDINAL FieldWidth;
  929. # endif
  930. {
  931.   IO_WriteI(f, n, FieldWidth);
  932. }
  933.  
  934. void IO_WriteCard
  935. # ifdef __STDC__
  936. (IO_tFile f, CARDINAL n, CARDINAL FieldWidth)
  937. # else
  938. (f, n, FieldWidth)
  939. IO_tFile f;
  940. CARDINAL n;
  941. CARDINAL FieldWidth;
  942. # endif
  943. {
  944.   INTEGER i;
  945.   CARDINAL length;
  946.   struct S_14 digits;
  947.  
  948.   length = 0;
  949.   do {
  950.     INC(length);
  951.     digits.A[length] = MyCHR.A[n % 10];
  952.     n = n / 10;
  953.   } while (!(n == 0));
  954.   {
  955.     LONGINT B_21 = 1, B_22 = (INTEGER)(FieldWidth - length);
  956.  
  957.     if (B_21 <= B_22)
  958.       for (i = B_21;; i += 1) {
  959.         IO_WriteC(f, ' ');
  960.         if (i >= B_22) break;
  961.       }
  962.   }
  963.   for (i = (INTEGER)length; i >= 1; i += -1) {
  964.     IO_WriteC(f, digits.A[i]);
  965.   }
  966. }
  967.  
  968. void IO_WriteNl
  969. # ifdef __STDC__
  970. (IO_tFile f)
  971. # else
  972. (f)
  973. IO_tFile f;
  974. # endif
  975. {
  976.   IO_WriteC(f, EolCh);
  977. }
  978.  
  979. void IO_CloseIO
  980. # ifdef __STDC__
  981. ()
  982. # else
  983. ()
  984. # endif
  985. {
  986.   IO_tFile i;
  987.  
  988.   for (i = 0; i <= System_cMaxFile; i += 1) {
  989.     {
  990.       register BufferDescriptor *W_14 = &BufferPool.A[i - -1];
  991.  
  992.       if (W_14->Buffer != NIL) {
  993.         if (W_14->OpenForOutput) {
  994.           IO_WriteClose(i);
  995.         } else {
  996.           IO_ReadClose(i);
  997.         }
  998.       }
  999.     }
  1000.   }
  1001. }
  1002.  
  1003. void BEGIN_IO()
  1004. {
  1005.   static BOOLEAN has_been_called = FALSE;
  1006.  
  1007.   if (!has_been_called) {
  1008.     has_been_called = TRUE;
  1009.  
  1010.     BEGIN_System();
  1011.     BEGIN_General();
  1012.     BEGIN_Memory();
  1013.     BEGIN_System();
  1014.  
  1015.     MyCHR.A[0] = '0';
  1016.     MyCHR.A[1] = '1';
  1017.     MyCHR.A[2] = '2';
  1018.     MyCHR.A[3] = '3';
  1019.     MyCHR.A[4] = '4';
  1020.     MyCHR.A[5] = '5';
  1021.     MyCHR.A[6] = '6';
  1022.     MyCHR.A[7] = '7';
  1023.     MyCHR.A[8] = '8';
  1024.     MyCHR.A[9] = '9';
  1025.     MyCHR.A[10] = 'A';
  1026.     MyCHR.A[11] = 'B';
  1027.     MyCHR.A[12] = 'C';
  1028.     MyCHR.A[13] = 'D';
  1029.     MyCHR.A[14] = 'E';
  1030.     MyCHR.A[15] = 'F';
  1031.     for (i = 0; i <= System_cMaxFile; i += 1) {
  1032.       {
  1033.         register BufferDescriptor *W_15 = &BufferPool.A[i - -1];
  1034.  
  1035.         W_15->Buffer = NIL;
  1036.         W_15->BufferIndex = 0;
  1037.         W_15->BytesRead = 0;
  1038.         W_15->OpenForOutput = FALSE;
  1039.         W_15->EndOfFile = FALSE;
  1040.         W_15->FlushLine = FALSE;
  1041.       }
  1042.     }
  1043.     BufferPool.A[IO_StdInput - -1].Buffer = (struct S_2 *)Memory_Alloc((LONGINT)(BufferSize + 1));
  1044.     BufferPool.A[IO_StdOutput - -1].Buffer = (struct S_2 *)Memory_Alloc((LONGINT)(BufferSize + 1));
  1045.     BufferPool.A[IO_StdError - -1].Buffer = (struct S_2 *)Memory_Alloc((LONGINT)(BufferSize + 1));
  1046.     BufferPool.A[IO_StdInput - -1].OpenForOutput = FALSE;
  1047.     BufferPool.A[IO_StdOutput - -1].OpenForOutput = TRUE;
  1048.     BufferPool.A[IO_StdError - -1].OpenForOutput = TRUE;
  1049.     CheckFlushLine((System_tFile)IO_StdInput);
  1050.     CheckFlushLine((System_tFile)IO_StdOutput);
  1051.     CheckFlushLine((System_tFile)IO_StdError);
  1052.   }
  1053. }
  1054.